package com.codelathe.gwt.client;


import com.google.gwt.user.client.Element;
import com.google.gwt.user.client.DOM;
import com.google.gwt.user.client.Window;
import com.google.gwt.user.client.ui.RootPanel;


/*
 * Test program for SoundManager
 */
public class TestSound extends SoundListenerAdapter {
	private SoundManager smobj;
	private Sound sobj;
	private SoundManagerListenerAdapter smadapter;

	
	public TestSound() {
		smadapter = new SoundManagerListenerAdapter();
		// SoundManager.setSoundManagerListener( smadapter);
		smobj = SoundManager.createInstance();

		smobj.setSoundListener( this);

		sobj = smobj.createSound( "76", "dream.mp3");
		sobj.play();
	}

	
	public void whilePlaying() {
		// Window.alert( "playing-" + sobj.getBytesLoaded() + " | " + sobj.getTotalBytes());
	}

	public void onLoadComplete() {
		// Window.alert("Loaded-" + sobj.getReadyState());
	}

	public void stop() {
		// sobj.stop();
		// smobj.stop("76");
		smobj.destroySound("76");
		// sobj.stop();
		// sobj.destruct();
		// sobj = smobj.createSound("76",
		// "http://127.0.0.1:10001/app/jukebox/getsong");
		// sobj.play();

	}

	public void onPlayStart() {
		// Window.alert("start-"+sobj.getPosition());
	}

	public void onPlayStop() {
		// Window.alert("stop-"+sobj.getPosition());
	}

	public void whileLoading() {
		// Window.alert("loading-"+sobj.getPosition());
	}

	// Tried to load script dynamically....Didn't work
	public void loadScript(String source) {
		Element script = DOM.createElement( "script");
		DOM.setElementAttribute( script, "src", source);
		DOM.appendChild( RootPanel.getBodyElement(), script);
	}
}